package com.google.donutrush;

import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.google.appengine.repackaged.org.json.JSONException;
import com.google.appengine.repackaged.org.json.JSONObject;

public class ErrorServlet extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response){
		ServletContext context = getServletContext();
		String error = (String) context.getAttribute("error");
		
		//creating the json to be sent to client
		JSONObject newJsonObject=new JSONObject();
		 
				try {
					newJsonObject.put("error", error);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			

		
		//from here is just the way to sent the json back to the client
		response.setContentType("text/plain");
		PrintWriter writer = null;
		try {
			writer = response.getWriter();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String myString = newJsonObject.toString();
		writer.println(myString);
		writer.close();
		//and.. sent

	}
	
}
